﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using Timesheet.Domain;
using System.Collections.Generic;

namespace Timesheet.WebForm.Report
{
    public partial class rpttmsh : DevExpress.XtraReports.UI.XtraReport
    {
        private List<XRTableCell> listDays = new List<XRTableCell>();
        public rpttmsh()
        {
            InitializeComponent();

            listDays.Add(lblValueSun);
            listDays.Add(lblValueMon);
            listDays.Add(lblValueTue);
            listDays.Add(lblValueWed);
            listDays.Add(lblValueThu);
            listDays.Add(lblValueFri);
            listDays.Add(lblValueSat);
        }

        public void setHeaderForReport(rptProject project, Domain.TimeSheets _currentTmsh, string location)
        {
            jobNum.Text = project.JobInfo;

            customer.Text =  project.CustomerInfo;

            locations.Text =  location;

            contactNo.Text =  project.Contact;

            netCode.Text =  project.NetCode;

            ResPerson.Text =  project.ResponsePerson;

            jobDes.Text =  project.JobDes;

            WBS.Text = project.Wbs;
           
            ticketNo.Text =  project.JobInfo + "-" + project.Ticket;

            weekEnding.Text = _currentTmsh.To.ToString("dd-MMM-yy");

            lblTeams.Text = project.TeamName;

          

            int count = 0;

            for (DateTime i = _currentTmsh.From; i <= _currentTmsh.To; i = i.AddDays(1))
            {
                listDays[count++].Text = i.ToString("MMM-dd");
            }
        }

        private decimal totalMileage = 0;
        private void xrTableCell15_SummaryGetResult(object sender, SummaryGetResultEventArgs e)
        {
            try
            {
                e.Result = string.Format("{0:0,0.#}", totalMileage);
            }
            catch
            {
                e.Result = 0d;
            }
            e.Handled = true;
        }

        private void xrTableCell15_SummaryReset(object sender, EventArgs e)
        {
            totalMileage = 0;
        }

        private void xrTableCell15_SummaryRowChanged(object sender, EventArgs e)
        {
            decimal value = 0;
            object temp = GetCurrentColumnValue("Mileage");
            if (temp == null)
                value = 0;
            else
                Decimal.TryParse(temp.ToString(), out  value);

            totalMileage += value;

        }
    }
}
